package com.yzh.pinboard.BoardView;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Created by Rex on 2017/2/22.
 */

public class Clip extends ClipData {


    private Bitmap picBitmap;
    private String picPath;

    public int clipWidth;
    public int clipHeight;
    public float minOffsetX;
    public float minOffsetY;

    public List<List<Stroke>> undoClip = new ArrayList<>();
    public List<List<Stroke>> redoClips = new ArrayList<>();
    public int undoIndex;
    public int redoIndex;


    public Clip(Bitmap picBitmap) {
        this.picBitmap = picBitmap;
    }

    public Clip(String picPath) {
        this.picPath = picPath;
    }

    public Clip(int width, int height) {
        this.id = UUID.randomUUID().toString();
        this.matrix.m11 = 1;
        this.matrix.m12 = 1;
        this.matrix.m21 = 1;
        this.matrix.m22 = 1;
        this.matrix.offsetX = 0;
        this.matrix.offsetY = 0;
        this.clipWidth = width;
        this.clipHeight = height;
        this.minOffsetX = 0;
        this.minOffsetY = 0;
        this.undoIndex = -1;
        this.elements = new ArrayList<>();
    }

    //public void undo
    public Bitmap getBitmap() {
        Paint strokePaint = new Paint();
        strokePaint.setColor(Color.BLACK);
        strokePaint.setStrokeJoin(Paint.Join.ROUND);
        strokePaint.setStrokeCap(Paint.Cap.ROUND);
        strokePaint.setStyle(Paint.Style.STROKE);
        Bitmap reBitmap = Bitmap.createBitmap(this.clipWidth, this.clipHeight, Bitmap.Config
                .ARGB_4444);
        ClipOperate.drawElement(this, reBitmap);
        ClipOperate.drawClip(this, reBitmap, strokePaint);
        return reBitmap;
    }

    public Bitmap getPicBitmap() {
        return picBitmap;
    }

    public void setPicBitmap(Bitmap picBitmap) {
        this.picBitmap = picBitmap;
    }

    public String getPicPath() {
        return picPath;
    }

    public void setPicPath(String picPath) {
        this.picPath = picPath;
    }
}
